exports.title = "微信跳一跳";
exports.description = "打开微信跳一跳会自动跳\n不使用时请禁用，以免影响其它小游戏的使用\n参数说明:\n跳跃距离=基数+倍数*距离";
exports.package = ["com.tencent.mm", "android"];
exports.params = [{
    key: "w",
    name: "倍数",
    value: 2.55
}, {
    key: "b",
    name: "基数",
    value: 55
}];

exports.script = function(shell, param) {
    return {
        TYPE_WINDOW_STATE_CHANGED(data) {
            // 窗口切换
            if (data.className == "com.tencent.mm.plugin.appbrand.ui.AppBrandUI") {
                // 小程序页面
                console.log("启动", param);
                shell.sleep(1500);
                this.start();
            }
        },
        start() {
            if (this.retry == 2) {
                this.retry = 0;
                console.log("失败两次，不再执行");
            } else {
                var v = shell.wechatJump(parseFloat(param.w), parseInt(param.b));
                if (v <= 0) {
                    this.less = false;
                    this.retry = this.retry ? this.retry + 1 : 1;
                    this.restart();
                    console.log("失败一次，点击重新开始试试");
                } else if (!this.less && v <= 120) {
                    this.less = true;
                    console.log("小于120", "");
                } else {
                    this.less = false;
                    this.retry = 0;
                    this.jump(v);
                    console.log("成功,长按", v, "毫秒");
                }
                shell.sleep(1000);
            }
        },
        jump(v) {
            var s = shell.getSize();
            s = s.split(",");
            var w = s[0] / 2;
            var h = s[1] / 2;
            shell.swipe(w, h, w, h, v);
        },
        restart() {
            var s = shell.getSize();
            s = s.split(",");
            var w = s[0] / 2;
            var h = s[1] * 0.8265625;
            shell.swipe(w, h, w, h, 100);
        },
        run: function() {
            shell.open("com.tencent.mm");
        }
    };
};